<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/10
 * Time: 17:26
 */

namespace App\Services;

use App\Models\AttachsDownloadLog;

class AttachsDownloadLogService extends BaseService
{
    protected $modelClass = AttachsDownloadLog::class;

    /**
     * 添加
     * @param $postData
     * @return bool|string
     * @throws \Exception
     */
    public function add($postData)
    {
        $postData['uuid'] = uuid();

        return $this->saveData($postData);
    }

    /**
     * 今天下载的附件
     * @param $staff_uuid
     */
    public function todayDown($staff_uuid)
    {
        $today = date('Y-m-d');
        $this->model->where('creator_uuid', $staff_uuid)
            ->where('created_at', 'like', "{$today}%")
            ->groupBy('attach_uuid')
            ->get();
    }

    /**
     * @desc 列表
     * @param array $search
     * @param int $per_page
     * @return array
     */
    public function getList($search=[], $per_page=20)
    {
        $columns = ['*'];

        $model = $this->searcher($this->model, $search);

        $conf = [
            'search'  => 'conf_search.download_getList',
            'columns' => 'conf_columns.download_getList',
            'buttons' => 'conf_buttons.download_getList',
        ];
        return $this->get_paginate($model->paginate($per_page, $columns), $conf);
    }

}